package com.hs.mobile.service.device;

import java.util.List;

import com.hs.mobile.model.Device;
import com.hs.mobile.model.ServiceMB;
import com.hs.mobile.dao.device.DeviceDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("deviceService")
public class DeviceServiceImpl implements DeviceService {
	
	@Autowired
	DeviceDAO deviceDAO;
	/**
	 * @name setDeviceDAO
	 * @param deviceDAO
	 */
	public void setDeviceDAO( DeviceDAO deviceDAO )
	{
		this.deviceDAO = deviceDAO;
	}
	
	/**
	 * 
	 * @return deviceDAO
	 */
	public DeviceDAO getDeviceDAO()
	{
		return deviceDAO;
	}
	
	@Override
	public void save(Device device) {
		// TODO Auto-generated method stub
		System.out.println("__ Save Device __");
		System.out.println("Device value :  " + device.getDeviceId() + ":::" + device.getStatus() + ":::" + device.getRegisterDate() );
		deviceDAO.add(device);
	}

	@Override
	public void update(Device device) {
		// TODO Auto-generated method stub
		System.out.println("__ update Device __ ");
		deviceDAO.update(device);
	}

	@Override
	public void delete(long id) {
		// TODO Auto-generated method stub
		System.out.println("__ Delete Device __");
		Device delDevice = (Device) deviceDAO.findByDeviceId(id);
		deviceDAO.delete(delDevice);
	}

	@Override
	public Device findDeviceById(long id) {
		// TODO Auto-generated method stub
		System.out.println("__ find Device __ ");
		Device device = (Device)deviceDAO.findByDeviceId(id);
		return device;
	}

	@Override
	public List<Device> getAllDevices() {
		// TODO Auto-generated method stub
		System.out.println("__ get totally Devices __ ");
		List<Device> liseDevices = deviceDAO.getListAll();
		return liseDevices;
	}

	@Override
	public List<Device> getAllAvailableDevices() {
		// TODO Auto-generated method stub
		System.out.println("__ get totally available Devices __ ");
		List<Device> listDevices = deviceDAO.getListAllAvailableDevices();
		return listDevices;
	}

	@Override
	public List<Device> getDeviceByIdGCM(String idGCM) {
		// TODO Auto-generated method stub
		System.out.println("__ get totally Devices by idGCM __");
		List<Device> listDevices = deviceDAO.getDeviceByIdGCM(idGCM);
		return listDevices;
	}

	@Override
	public List<ServiceMB> getListRegisteredDevice(long id) {
		// TODO Auto-generated method stub
		return deviceDAO.getListServiceUserRegister(id);
	}

}
